package com.hafu.dao;

import com.hafu.model.Khinfo;
import com.hafu.util.DbUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class KhinfoDao {
    //添加客户信息
    public Boolean addKhinfo(Khinfo kh)
    {
    	String sql ="insert into kh_info values(null,?.?)";
        Connection conn = DbUtil.getConn();
        try {
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setString(1,kh.getName());
            preparedStatement.setString(2,kh.getTel());
            //执行添加sql方法
            int i = preparedStatement.executeUpdate();
            if (i>0){
                System.out.println("添加成功");
                return true;
            }else return false;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return false;
    }
    //根据客户id删除客户
    public Boolean deleteKhinfo(int id)
    {
    	String sql ="delete from kh_info where id=?";
        Connection conn = DbUtil.getConn();
        try {
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setInt(1,id);
            int i = preparedStatement.executeUpdate();
            if (i>0){
                System.out.println("删除成功");
                return true;
            }else return false;
        }catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return false;
    }
}
